//app.js
const cloudsets = require('_self/application.js').CloudSetting;
const cloud = require('_self/cloud.js');
App({
  token:"", //临时通行证
  xh:"",
  sel_item: {
    id:'0',
    name:'山东科技大学',
    // imgurl 是校徽图片
    imgurl:'https://s1.ax1x.com/2020/04/30/JLGD3V.jpg',
    //api 教务系统地址，建议使用 域名形式
    api:'http://jwgl.sdust.edu.cn/app.do?',
    jxl:[
      "J1", "J3", "J5", "J7", "J11", "J13", "J14", "J15", "S1"
    ],//教学楼
    jxlid:[
      "1", "3", "5", "7", "11", "13", "14", "15", "S1"
    ],//教学楼对应id
  }, //选择的学校信息
  onLaunch: function(options) {
    //此处需要有对进入小程序方式的处理
    this.InitCloud(); //初始化云服务 / ESC
    this.InitCustom(); //初始化custom所需配置信息
  },
  InitCloud() {
    var that = this;
    wx.getStorage({
      key: 'wxuserinfo',
      success: function (res) {
        that.globalData.userInfo = res.data
      },
    })
    if (cloudsets.UseCloud) {
      console.log('* 云开发 * √' + ' 服务器:' + cloudsets.CloudId)
      if (!wx.cloud) {
        console.log(' -- 不支持云开发 -- ')
      } else {
        wx.cloud.init({
          env: cloudsets.CloudId,
          traceUser: cloudsets.TraceUser
        })
        //缓存信息
        cloud.CallCloudFuncAndSetStorge('openapi', cloudsets.AdaptStorge, 'userinfo',{action:'getOpenData'}).then(function (res) {
          if (res != 'callfuncfail') {
            //console.log(res)
            that.globalData.openid = res //给全局变量 openid 赋值
          }
        })

      }
    } else {
      console.log('* 云开发 * X')

    }
  },
  InitCustom(){
    wx.getSystemInfo({
      success: e => {
        //console.log(e)
        this.globalData.StatusBar = e.statusBarHeight;
        let custom = wx.getMenuButtonBoundingClientRect();
        // console.log(custom)
        this.globalData.Custom = custom;
        this.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
      }
    })
  },
  globalData: {}
})